package com.zr.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zr.model.Course;
import com.zr.model.User;
import com.zr.service.CourseServise;
import com.zr.service.StudentService;
import com.zr.serviceImpl.CourseServiseImpl;
import com.zr.serviceImpl.StudentServiseImpl;

import net.sf.json.JSONArray;




public class ChooseCourseControllerWWQ extends HttpServlet{
	 StudentService stus=new StudentServiseImpl();

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("utf8");
		resp.setCharacterEncoding("utf8");
		HttpSession session=req.getSession();
		User u=(User) session.getAttribute("User");
		int sid=u.getSid();
		int cid=Integer.parseInt(req.getParameter("cid"));
		boolean  flag = stus.addCourseByCid(sid, cid);
		PrintWriter pw=resp.getWriter();
		if(flag){
			pw.write("1");
		}
//		else{
//			pw.write("2");
//		}
       
	}
}
